﻿using System.Xml.Serialization;

namespace NaverOpenApiLibrary.Models
{
    [XmlRootAttribute("result", IsNullable=false)]
    public class HotTopicsWrapper
    {
        public HotTopic this[int i]
        {
            get 
            {
                return HotTopics[i];
            }
        }

        [XmlElementAttribute(ElementName="item")]
        public HotTopics HotTopics;
    }

    public class HotTopics // : IEnumerable
    {
        // indexer
        public HotTopic this[int i]
        {
            get 
            {
                HotTopic topicToReturn;
                switch (i)
                { 
                    case 0:
                        topicToReturn = HotTopic1;
                        break;
                    case 1:
                        topicToReturn = HotTopic2;
                        break;
                    case 2:
                        topicToReturn = HotTopic3;
                        break;
                    case 3:
                        topicToReturn = HotTopic4;
                        break;
                    case 4:
                        topicToReturn = HotTopic5;
                        break;
                    case 5:
                        topicToReturn = HotTopic6;
                        break;
                    case 6:
                        topicToReturn = HotTopic7;
                        break;
                    case 7:
                        topicToReturn = HotTopic8;
                        break;
                    case 8:
                        topicToReturn = HotTopic9;
                        break;
                    case 9:
                        topicToReturn = HotTopic10;
                        break;

                    default:
                        topicToReturn = null;
                        break;
                }
                return topicToReturn;
            }
        }

        [XmlElementAttribute(ElementName = "R1")]
        public HotTopic HotTopic1;

        [XmlElementAttribute(ElementName = "R2")]
        public HotTopic HotTopic2;

        [XmlElementAttribute(ElementName = "R3")]
        public HotTopic HotTopic3;

        [XmlElementAttribute(ElementName = "R4")]
        public HotTopic HotTopic4;

        [XmlElementAttribute(ElementName = "R5")]
        public HotTopic HotTopic5;

        [XmlElementAttribute(ElementName = "R6")]
        public HotTopic HotTopic6;

        [XmlElementAttribute(ElementName = "R7")]
        public HotTopic HotTopic7;

        [XmlElementAttribute(ElementName = "R8")]
        public HotTopic HotTopic8;

        [XmlElementAttribute(ElementName = "R9")]
        public HotTopic HotTopic9;

        [XmlElementAttribute(ElementName = "R10")]
        public HotTopic HotTopic10;


        #region IEnumerator / IEnumerable Implementation

        //public IEnumerator GetEnumerator()
        //{
        //    return new HotTopicEnumerator(this);
        //}

        
        //class HotTopicEnumerator : IEnumerator
        //{
        //    [XmlIgnore]
        //    public const int MAX_HOT_TOPICS = 10;
        //    private HotTopics _hotTopics;
        //    private int _position = -1;

        //    public HotTopicEnumerator(HotTopics hotTopics)
        //    {
        //        this._hotTopics = hotTopics;
        //    }

        //    [XmlIgnore]
        //    public object Current
        //    {
        //        get { return _hotTopics[_position]; }
        //    }

        //    public bool MoveNext()
        //    {
        //        if (_position < MAX_HOT_TOPICS)
        //        {
        //            _position++;
        //            return true;
        //        }
        //        else
        //        {
        //            return false;
        //        }
        //    }

        //    public void Reset()
        //    {
        //        _position = -1;
        //    }

        //}

        #endregion
    }

    public class HotTopic
    {
        [XmlElementAttribute(ElementName = "K")]
        public string Keyword;
        [XmlElementAttribute(ElementName = "S")]
        public string RankUpDown;
        [XmlElementAttribute(ElementName = "V")]
        public string RankDelta;
    }
}
